<template>
	<view>
		<view class="scroll-view-container">
			<!-- 左侧滑动区域 -->
			<scroll-view scroll-y="true" class="left-sc-view" :style="{height:wh+'px'}">
				<block v-for="(item,index) in cateList" :key="index">
					<view :class="['sc-view-item', index === active ? 'active' : '']" @click="activehandle(index)">
						{{item.cat_name}}</view>
				</block>

			</scroll-view>
			<!-- 右侧滑动区域 -->
			<scroll-view scroll-y="true" :style="{height:wh+'px'}">
				<view class="cate-list2" v-for="(item,index) in catelist2" :key="index">
					<!-- 二级分类的标题 -->
					<view class="cate-list2-title">
						/ {{item.cat_name}} /
					</view>
					<view class="cate-list3">
						<!-- 三级分类的item -->
						<view class="cate-list3-item" v-for="(item1,index1) in item.children" :key="index1">
							<!-- 三级分类的图片 -->
							<image :src="item1.cat_icon.replace('dev','web')" mode=""></image>
							<!-- 解决三级分类图片显示不正确，试试<image :src="item3.cat_icon.replace('dev','web')"></image> -->
							<!-- 三级分类的文本 -->
							<text>{{item1.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getcateList
	} from "../../api/cate.js"

	export default {
		data() {
			return {
				wh: '', //当前设备可用的高度
				cateList: [], //分类列表数据
				active: 0, //当前选中的分类列表
				catelist2: [], //二级分类
				catelist3: [], //三级分类

			};
		},
		async onLoad() {
			const sysinfo = await uni.getSystemInfoAsync() //获取手机型号可用屏幕高度
			this.wh = sysinfo.windowHeight
			this.getcate()
		},
		methods: {
			async getcate() {
				let data = await getcateList()
				console.log(data);
				if (data.statusCode !== 200) {
					return uni.$showMsg
				} else {
					this.cateList = JSON.parse(JSON.stringify(data.data.message))
					// console.log(this.cateList);
					// 二级分类赋值
					this.catelist2 = JSON.parse(JSON.stringify(this.cateList[0].children))
					// this.catelist2 = toRaw(data.data.message)
					// this.catelist2 = JSON.parse(JSON.stringify(data.data.message))[0].children
					// this.catelist2 =  JSON.parse(JSON.stringify(this.catelist2))

					console.log(this.catelist2);

				}

			},
			activehandle(i) {
				this.active = i
				this.catelist2 = this.cateList[i].children
			}
		}
	}
</script>

<style lang="scss">
	.scroll-view-container {
		display: flex;
	}

	.left-sc-view {
		width: 30vw;

	}

	.sc-view-item {
		background-color: #f7f7f7;
		line-height: 60px;
		text-align: center;
		font-size: 12px;

		&.active {
			background-color: #ffffff;
			position: relative;

			&::before {
				content: ' ';
				display: block;
				width: 3px;
				height: 30px;
				background-color: #c00000;
				position: absolute;
				top: 50%;
				left: 0;
				transform: translateY(-50%);

			}
		}
	}

	.cate-list2-title {
		font-size: 12px;
		font-weight: bold;
		text-align: center;
		padding: 15px 0;
	}

	.cate-list3 {
		display: flex;
		flex-wrap: wrap;

		.cate-list3-item {
			width: 33.33%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-bottom: 10px;

			image {
				width: 60px;
				height: 60px;
			}

			text {
				font-size: 12px;
			}
		}
	}
</style>
